#
# Make file to build the PostGreSQL 7 Database Driver for DBConnect API
# Copyright (c) Johnathan Ingram 2003
#
# dynamic: Build the driver requiring the postgreSQL dynamic link library.
# static:  Build the driver allowing driver to run on machines without 
#          postgreSQL installed. Statically links postgreSQL symbols into driver.
#
#####################################################################

SHELL = /bin/sh

top_srcdir = @top_srcdir@
CC = @CC@
CXX = @CXX@
CPPFLAGS = @CPPFLAGS@
CFLAGS = -fPIC $(CPPFLAGS) @CFLAGS@ @OS_DEF@ -DDBCONNECTVER='"@dbconn_version@"'
LINKER_FLAGS = @LINKER_FLAGS@
IFLAGS = -I../base -I@pgsql_include@

SOURCES = pgsqlConnection.cpp pgsqlQuery.cpp pgsqlBindParam.cpp pgsqlValue.cpp
LIB_OBJS = $(SOURCES:.cpp=.o)
LIB_OBJS += main_so.o

all: @pgsql_target@
	cp -f ./dbconndrv-postgresql-@dbconn_version@@SO_EXT@ $(top_srcdir)/lib/drivers
	cd $(top_srcdir)/lib/drivers && ln -sf dbconndrv-postgresql-@dbconn_version@@SO_EXT@ dbconndrv-postgresql@SO_EXT@ && cd -

static: $(LIB_OBJS)
	gcc @SO_FLAG@ $(LINKER_FLAGS) \
	-o dbconndrv-postgresql-@dbconn_version@@SO_EXT@ $(LIB_OBJS) \
	@pgsql_lib@/@pgsql_libfile@ @LIBS@ \
	-L../dbconnect -ldbconnect-@dbconn_version@

dynamic: $(LIB_OBJS)
	gcc @SO_FLAG@ $(LINKER_FLAGS) \
	-o dbconndrv-postgresql-@dbconn_version@@SO_EXT@ $(LIB_OBJS) \
	@LIBS@ -L@pgsql_lib@ -l@pgsql_libfile@ \
	-L../dbconnect -ldbconnect-@dbconn_version@

clean:
	rm -f *.o
	rm -f *.so
	rm -f $(top_srcdir)/lib/drivers/dbconndrv-postgresql-@dbconn_version@@SO_EXT@


main_so.o: main_so.cpp
	$(CXX) -c main_so.cpp $(CFLAGS) $(IFLAGS) -o main_so.o


%.o: %.cpp %.h
	$(CXX) -c $< $(CFLAGS) $(IFLAGS) -o $@
